﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MobileASP
{
    public partial class WebFormPublish : System.Web.UI.Page
    {
        List<Producer> producers = new List<Producer>();
        
        protected void Page_Load(object sender, EventArgs e)
        {
            List<string> models = new List<string>() { "A4", "A6", "A8", "80", "100", };
            producers.Add(new Producer("Audi", models));

            models = new List<string>() { "315", "316", "318", "320", "323", "324" };
            producers.Add(new Producer("BMW", models));

            models = new List<string>() { "C200", "C220", "C230", "C240", "S280", };
            producers.Add(new Producer("Mercedes", models));

            models = new List<string>() { "Astra", "Corsa", "Vectra", "Insignia" };
            producers.Add(new Producer("Opel", models));

            List<string> extras = new List<string>() { "2(3) doors", "4(5) doors", "4x4", "ABS", "Airbag", "Metalic", 
                "GPS", "Parktronic", "Stereo", };

            string[] engine = { "Petrol", "Diesel", "Hybrid", "Electrics", };

            if (!Page.IsPostBack)
            {
                this.dropDownProducers.DataSource = producers;
                this.dropDownProducers.DataTextField = "Name";
                this.checkBoxExtras.DataSource = extras;
                this.radioButtonEngine.DataSource = engine;
                DataBind();
            }
        }

        protected void dropDownProducers_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.DropDownModels.DataSource = this.producers[this.dropDownProducers.SelectedIndex].Models;
            DataBind();
        }

        protected void DropDownModels_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.checkBoxExtras.Enabled = true;
            this.radioButtonEngine.Enabled = true;
        }

        protected void buttonSubmit_Click(object sender, EventArgs e)
        {
            string extras = String.Empty;

            for (int i = 0; i < this.checkBoxExtras.Items.Count; i++)
			{			 
                if (this.checkBoxExtras.Items[i].Selected)
                {
                    extras += this.checkBoxExtras.Items[i].Text + "; ";
                }
			}

            this.literal.Text = "You selected:<br />";
            this.literal.Text += "<b>Car:</b> " + this.dropDownProducers.SelectedItem.Text + " "
                + this.DropDownModels.SelectedItem.Text + "<br />";
            this.literal.Text += "<b>Extras:</b> " + extras + "<br />";
            this.literal.Text += "<b>Engine type:</b> " + this.radioButtonEngine.SelectedItem.Text + "<br />";
        }

        protected void radioButtonEngine_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.buttonSubmit.Enabled = true;
        }
    }
}